import java.io.*;

/**
 * Created by sunyi on 10/29/2015.
 */
public class ConvertAd {

    //给出一个csv转换为libsvm文件的工具  第一个参数为源文件  第二个为目标文件，第三个为分隔符，第四个为目标字段的位置
    public static void main(String[] args)
    {
        try
        {
            DataInputStream in = new DataInputStream(new FileInputStream(new File(args[0])));
            BufferedReader reader = new BufferedReader(new InputStreamReader(in,"UTF-8"));

            //打开输出文件
            DataOutputStream out = new DataOutputStream(new FileOutputStream(args[1]));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out,"UTF-8"));

            reader.readLine();//第一行信息，为标题信息，不用,如果需要，注释掉
            String line = null;
            while((line = reader.readLine()) != null)
            {
                String item[] = line.split("\\t");//CSV格式文件为逗号分隔符文件，这里根据逗号切分


                //int value = Integer.parseInt(last);//如果是数值，可以转化为数值

                for(int i = 0;i < item.length; i++)
                {
                    String item2[] = item[i].split("_");
                    //写入文件
                    String result = item2[0] + "," + item2[1] + '\n';
                    writer.write(result);

                }


            }


            //释放内存

            reader.close();
            writer.close();
            out.close();
            in.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }


    }
}
